package com.example.superoa.model.service;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.dao.DepartmentDao;
import com.example.superoa.model.dao.PositionDao;
import com.example.superoa.model.dao.RplanDao;
import com.example.superoa.model.dao.StaffDao;
import com.example.superoa.model.mappers.RplanMapper;
import com.example.superoa.model.pojos.Rplan;

@Service
@Transactional(rollbackFor=Exception.class)
public class RplanService {
		@Autowired
		private RplanDao plandao;
		@Autowired
		private RplanMapper planmapper;		
		@Autowired
		private DepartmentDao d_dao;
		@Autowired
		private PositionDao  p_dao;
		@Autowired
		private StaffDao s_dao;
		//查询所有
		public JSONArray biofindAllplan() {
			return planmapper.findAllsplan();
		}		
		//查询计划详情
		public JSONArray findByIdplan(int rplanid) {
			return planmapper.findByIdplan(rplanid);
		}
			//新增项目
		public void addprogram(Rplan plan,int staff_id,int post_id,int dept_id) {
			plan.setDepartment(d_dao.findById(dept_id).get());
			plan.setPosition(p_dao.findById(post_id).get());
			plan.setStaff(s_dao.findById(staff_id).get());
			plan.setRplanqi(0);
			plandao.save(plan);
		}
		//启用计划
		public void Qi(int id,int qi) {
			Rplan rplan=plandao.findById(id).get();
			if(qi==0) {
				rplan.setRplanqi(1);
			}else {
				rplan.setRplanqi(0);
			}
			plandao.save(rplan);
		}
		//初始化
				public JSONArray selectbyplanid(int rplanid) {
					return planmapper.findByIdplan(rplanid);
				}
				//修改试卷
		public void xiugaiplan(int rplanid, String rplanname, Date rplanstart, Date rplanend, Date rplanexitstart,
				Date rplanexitend, String rplanway, BigDecimal rplanmoney, BigDecimal rplanexitmoney) {
				Rplan plan = plandao.findById(rplanid).get();
				plan.setRplanname(rplanname);
				plan.setRplanexitstart(rplanexitstart);
				plan.setRplanexitend(rplanexitend);
				plan.setRplanexitmoney(rplanexitmoney);
				plan.setRplanmoney(rplanmoney);
				plan.setRplanend(rplanend);
				plan.setRplanstart(rplanstart);
				plan.setRplanway(rplanway);
				plandao.save(plan);
		}		
}